home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 7_10.lha / 7_10 / p_schedule.c < prev    next >
Text File  |  1993-08-08  |  1KB  |  47 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <process.h>
  6. include <debug.h>    /* DELETE */
  7. / Find the next class to run and call restore() on it
  8. oid process::schedule()
  9.  
  10.    if (debug) /*DELETE*/ cerr << "process" << this << "::schedule()\n";
  11.    if (debug) /*DELETE*/ dumpall(cerr);
  12.    // Make sure t_thisprocess is saved on the run list.
  13.    if (t_thisprocess &&
  14. t_thisprocess->t_curstate == TASK_CURRENT)
  15. {
  16. t_thisprocess->t_next = t_runprocesses;
  17. t_desiredtime = 0;
  18. t_runprocesses = t_thisprocess;
  19. shufflerunlist();
  20. }
  21.  
  22.    if (!t_runprocesses)
  23. {
  24. if (t_exit_fct)
  25.     (*t_exit_fct)();
  26.  
  27. if (debug) /*DELETE*/ cerr << "There are no runnable processes\n";
  28. if (t_mainprocess->t_curstate == TASK_TERMINATED)
  29.     ::exit((int)(t_mainprocess->t_result));
  30. else
  31.     ::exit(1);
  32. }
  33.  
  34.    // Now pull off the top process from
  35.    // t_runprocesses and restore it
  36.    if (debug) /*DELETE*/ dumpall(cerr);
  37.    process *res = t_runprocesses;
  38.    if (debug) /*DELETE*/ cerr << "<<<< process" << this << "::schedule() <- " << res << "\n";
  39.    t_runprocesses = t_runprocesses->t_next;
  40.    if (res->t_desiredtime > 0)
  41. t_curtime = res->t_desiredtime;
  42.    res->t_next = 0;
  43.    res->t_desiredtime = 0;
  44.    res->t_curstate = TASK_CURRENT;
  45.    res->restore();
  46.  
  47.